package io.renren.modules.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.basic.dao.MtCcTaskRunInfoLogDao;
import io.renren.modules.basic.entity.MtCcTaskRunInfoLogEntity;
import io.renren.modules.basic.service.MtCcTaskRunInfoLogService;
import org.springframework.stereotype.Service;

import java.util.Map;




@Service("mtCcTaskRunInfoLogService")
public class MtCcTaskRunInfoLogServiceImpl extends ServiceImpl<MtCcTaskRunInfoLogDao, MtCcTaskRunInfoLogEntity> implements MtCcTaskRunInfoLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        /**
         * 条件：
         *      单号       task_code
         *      出入库     task_type
         *      操作人（出入口）     user_id
         *      开始时间    start_time
         *      结束时间    end_time
         */
        String startTime = String.valueOf(params.get("startTime"));
        String endTime = String.valueOf(params.get("endTime"));
        String entryGate = String.valueOf(params.get("entryGate"));
        String oType = String.valueOf(params.get("oType"));
        /*if(startTime.equals("")&&entryGate.equals("")&&oType.equals("")){
            IPage<MtCcTaskRunInfoLogEntity> page = this.page(
                    new Query<MtCcTaskRunInfoLogEntity>().getPage(params),
                    new QueryWrapper<MtCcTaskRunInfoLogEntity>()
            );
            return new PageUtils(page);
        }*/
        boolean boolOType = oType.equals("null")||oType.equals("");
        boolean boolEntryGate=entryGate.equals("null")||entryGate.equals("");
        boolean boolStartTime = startTime.equals("null")||startTime.equals("");
        IPage<MtCcTaskRunInfoLogEntity> page = this.page(
                new Query<MtCcTaskRunInfoLogEntity>().getPage(params),
                new QueryWrapper<MtCcTaskRunInfoLogEntity>()
                        .eq(!boolOType,"task_type",oType)
                        .like(!boolEntryGate,"task_code",entryGate)
                        .between(!boolStartTime,"create_time",startTime,endTime)
                        .orderByAsc("id")
        );
                    return new PageUtils(page);
        }

}